/*
 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <gtest/gtest.h>
#include "sle_ssap_client_service.h"
#include "cmd_input.h"
#include <vector>
#include <memory>
#include <cstring>
#include <iterator>

namespace OHOS {
namespace NearLink {
namespace SleStandard {
namespace {
using namespace testing::ext;
SleSsapClientService *clientService_ = nullptr;
uint8_t clientId = 255;
} // namespace

class SsapcHandlerTest : public testing::Test {
public:
    static void SetUpTestCase();
    static void TearDownTestCase();
    void SetUp();
    void TearDown();
};

void SsapcHandlerTest::SetUpTestCase() {}

void SsapcHandlerTest::TearDownTestCase() {}

void SsapcHandlerTest::SetUp() {
    clientService_ = SleSsapClientService::GetInstance();
}

void SsapcHandlerTest::TearDown() {}

HWTEST_F(SsapcHandlerTest, FindSsapStructureTest, TestSize.Level1)
{
    ClientFindStructure paramFind;
    paramFind.findType = (SsapFindType )1;
    paramFind.startHandle = (uint16_t)1;
    paramFind.endHandle = (uint16_t)1;
    uint16_t connectId = 255;
    SsapClientFindStructure params(paramFind);
    SleErrorCode ret = clientService_->FindSsapStructure(clientId, connectId, params);
    EXPECT_EQ(ret, SLE_ERR_FAILED);
}

HWTEST_F(SsapcHandlerTest, ReadReqByUuidTest, TestSize.Level1)
{
    uint16_t connectId = 255;
    ClientReadReqByUUID paramRead;
    paramRead.findType = (SsapFindType)1;
    paramRead.startHandle = (uint16_t)1;
    paramRead.endHandle = (uint16_t)1;
    paramRead.uuid.len = UUID_LEN;
    paramRead.uuid.uuid[0] = 0;
    SsapClientReadReqByUUID params(paramRead);
    SleErrorCode ret = clientService_->ReadRequestByUuid(clientId, connectId, params);
    EXPECT_EQ(ret, SLE_ERR_FAILED);
}

HWTEST_F(SsapcHandlerTest, ReadReqTest, TestSize.Level1)
{
    uint16_t connectId = 255;
    uint16_t handle = 123;  // 设置一个固定的 handle 值，例如 123
   // uint16_t handle = (uint16_t)SleGetInputNumber("please input handle: ");
    SleSsapPropertyType propertyTpye = (SleSsapPropertyType)1;
    SleErrorCode ret = clientService_->ReadRequest(clientId, connectId, handle, propertyTpye);

    EXPECT_EQ(ret, SLE_ERR_FAILED);
}

HWTEST_F(SsapcHandlerTest, WriteReqTest, TestSize.Level1)
{
    uint16_t connectId = 255;
    ClientWriteParam paramWrite;
    paramWrite.handle = (uint16_t)0;
    paramWrite.type = (SleSsapPropertyType)0;
    uint8_t data[256];
    const char* str = "nearlink test";
    strncpy(reinterpret_cast<char*>(data), str, sizeof(data));
    paramWrite.dataLength = strlen((char*)data) + 1;
    paramWrite.data = data;
    SsapClientHandleValue params(paramWrite);
    SleErrorCode ret = clientService_->WriteRequest(clientId, connectId, params);
    EXPECT_EQ(ret, SLE_ERR_FAILED);
}

HWTEST_F(SsapcHandlerTest, WriteCmdTest, TestSize.Level1)
{
    uint16_t connectId = 255;
    SsapClientHandleValue paramWrite;
    SleErrorCode ret = clientService_->WriteCommand(clientId, connectId, paramWrite);
    EXPECT_EQ(ret, SLE_ERR_FAILED);
}

HWTEST_F(SsapcHandlerTest, ExchangeInfoReqTest, TestSize.Level1)
{
    uint16_t connectId = 255;
    uint32_t mtu = 256;
    uint16_t version = 0;
    SleErrorCode ret = clientService_->ExchangeInfo(clientId, connectId, mtu, version);
    EXPECT_EQ(ret, SLE_ERR_FAILED);
}
}
} // namespace NetManagerStandard
} // namespace OHOS